package dubrouski.csc;

import dubrouski.triangulation.Vector3d;
import java.util.Objects;

/**
 *
 * @author Stanislau Dubrouski
 */
public class Shift implements Comparable<Shift> {

    private Vector3d begins;
    private Vector3d ends;

    public Shift(Vector3d begins, Vector3d ends) {
        this.begins = begins;
        this.ends = ends;
    }

    Shift(Shift get) {
        this.begins = new Vector3d(get.begins.getX(), get.begins.getY(), get.begins.getZ());
        this.ends = new Vector3d(get.ends.getX(), get.ends.getY(), get.ends.getZ());
    }

    public Vector3d getBeginVector() {
        return begins;
    }

    public void setBeginVector(Vector3d begin) {
        this.begins = begin;
    }

    public Vector3d getEndVector() {
        return ends;
    }

    public void setEndVector(Vector3d end) {
        this.ends = end;
    }

    /**
     * @param pair
     * @return Vector3d vector
     */
    public static Vector3d computeVectorValue(Shift pair) {
        return new Vector3d(
                pair.getEndVector().getX() - pair.getBeginVector().getX(),
                pair.getEndVector().getY() - pair.getBeginVector().getY(),
                pair.getEndVector().getZ() - pair.getBeginVector().getZ());
    }

    public int compareTo(Shift o) {
        Shift other = (Shift)o;
        return (int)(other.getBeginVector().getX() - this.begins.getX());
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 89 * hash + Objects.hashCode(this.begins);
        hash = 89 * hash + Objects.hashCode(this.ends);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Shift other = (Shift) obj;
        if (!Objects.equals(this.begins, other.begins)) {
            return false;
        }
        if (!Objects.equals(this.ends, other.ends)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Shift: begins {" + this.begins.toString() + "}, ends {" + this.ends.toString() + "};";
    }
}